// pages/integral/integral.js
const app = getApp()
var utils = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgPath: app.d.imgPath,
    desc:false,
    tabSelect: {
      select: 0, 
      xlup: false,
      jgup:false,
      xlSelect: true,
      jgSelect: false,
      img: '/images/goodslist/down.png',
      activeImg: '/images/goodslist/up.png'
    },

    goods: []


  },

  //点击tab
  tabClick(e) {
    // console.log(e.currentTarget.dataset.num)
    var that = this
    wx.showLoading({
      title: '加载中',
    })
    this.setData({
      'tabSelect.select': e.currentTarget.dataset.num
    })
    if (e.currentTarget.dataset.num == 1) {
      var desc = !this.data.tabSelect.xlup
      this.setData({
        'tabSelect.xlSelect': true,
        'tabSelect.xlup': !this.data.tabSelect.xlup,
        'tabSelect.jgSelect': false,
        'tabSelect.jgup': false,
      })
    } else if (e.currentTarget.dataset.num == 2) {
      var desc = !this.data.tabSelect.jgup
      this.setData({
        'tabSelect.xlSelect': false,
        'tabSelect.jgSelect': true,
        'tabSelect.jgup': !this.data.tabSelect.jgup,
        'tabSelect.xlup': false,
      })
    } else {
      var desc = ''
      this.setData({
        'tabSelect.jgSelect': false,
        'tabSelect.xlSelect': false,
        'tabSelect.xlup': false,
        'tabSelect.jgup': false,
      })
    }
    var sucFunc = function (that, res) {
      that.setData({
        goods: res.data,
      })

      wx.hideLoading();
    }
    var data = { sortId: that.data.sortId, type: e.currentTarget.dataset.num,desc:desc}
    utils.wxRequest(that, app.d.path, "Goods/goodslist", data, sucFunc);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  onLoad: function (options) {
    var that = this
    wx.showLoading({
      title: '加载中',
    })
    that.setData({
      sortId: options.id ,
    })
    var sucFunc = function (that, res) {
      that.setData({
        goods: res.data,
      })

      wx.hideLoading();
    }
    var data = { sortId: options.id }
    utils.wxRequest(that, app.d.path, "Goods/goodslist", data, sucFunc);
  },
  detail:function(e){
    var that = this;
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/pages/goodsDetail/goodsDetail?id=" + id
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})